Dynamic web page generation

ABSTRACT

Dynamic web page generation is optimized by reducing the processing overhead required to parse the web page HTML code for tokens and insert dynamic content. Using the invention, an HTML file for a dynamic web page need be read and parsed only once throughout the life of the server. A software object parses the HTML, decomposes the page into constituent pieces and saves them to data structures as byte streams, which are cached, along with the software object, rendering multiple disk accesses unnecessary when the page is reconstituted. For subsequent requests, the dynamic page is created from the cached version, which is shareable across users and across requests. The optimization reduces server resource usage for dynamic page generation to near zero. The invention is also applicable to other documents combining static and dynamic content that require composition tools for editing.

[0001] A portion of the disclosure of this patent document contains material that is subject to copyright protection. The copyright owner has no objection to the reproduction by anyone of the patent document or the patent disclosure, as it appears in the Patent and Trademark Office file or records, but otherwise reserves all copyright rights whatsoever.

BACKGROUND OF THE INVENTION

[0002] 1. Field of the Invention

[0003] The invention relates to processing of electronic documents. More particularly the invention relates to a method of optimizing generation of web pages having dynamic content.

[0004] 2. Description of Related Technology

[0005] Today's Internet websites must deliver an ever-increasing amount of dynamic web page content. Dynamic web page generation is the process whereby a server computer creates HTML “on the fly” to send to a client computer (a Web browser). Dynamic web pages differ from static web pages in that the content of a dynamic web page can only be determined the moment a page request is received by the server computer. While a static web page might display a biography of Abraham Lincoln, content which can be created once and not changed anymore, such a web page and methodology would not be suitable for a web page which displayed the current price of oranges at five local supermarkets. The latter case requires that the server computer utilize dynamic information and compose that information into a web page to send to a client computer.

[0006] A common practice employed to aid in the creation of dynamic web pages is the use of HTML containing “tokens”, or “tokenized HTML”. A tokenized HTML file contains some never-changing static information, for example a page heading with the word “Welcome” in it, but also contains some dynamic or “live” areas; for example, an area after “Welcome” where the user's name is to be dynamically placed. This will allow each user to see a Web page that is customized for them. When Sally visits this web page she'll be greeted with a page title that says “Welcome Sally”, and when Joe visits this web page it will be titled, “Welcome Joe”. One of the major advantages of using tokens as placeholders for dynamic content is that they are extremely unobtrusive, allowing technical personnel such as programmers to make sure that dynamic content is placed in certain areas of the page without the necessity of embedding complicated source code in the HTML, which may be very confusing and distracting to someone such as a graphic designer, who is tasked with maximizing the page's aesthetic appeal.

[0007] To serve up dynamic web pages, a web server typically creates a dynamic page by loading up a static HTML page with a “token” or “placeholder” in the area where the user's name went. The tokens are of a known form;, for example, “@UserName@,” so that they may be searched for quickly and uniquely. The server searches the page looking for the tokens that refer to dynamic content, e.g. “@UserName@.” Once the token has been located, the server replaces its text with the dynamically discovered text, e.g “Sally.” Replacing a token involves storing all of the text leading up to the token and concatenating it with the dynamic content and all of the text following the token. It must do this for each request it receives (each dynamic page that each user asks for).

[0008] Various methods of creating documents with varying content have been proposed. For example, J. Cooper, M. San Soucie, Method of generating document using tables storing pointers and indexes, U.S. Pat. No. 4,996, 662 (Feb. 26, 1991) describe a document processing system having a system architecture that includes a control structure providing supervisory routines for controlling supervisory functions of the system and document manipulation routines for operating upon the documents.

[0009] R. Smith, D. Ting, J. Boer, M. Mendelssohn, Document management and production system, U.S. Pat. No. 5,181,162 (Jan. 19, 1993) disclose an object-oriented document management and production system in which documents are represented as collections of logical components that may be combined and physically mapped onto a page-by-page layout.

[0010] D. Dodge, S. Follett, A. Grecco, J. Tillman, Method and apparatus for document production using common document database, U.S. Pat. No. 5,655,130 (Aug. 5, 1997) describe a system and method for producing a variety of documents from a common document database. In the described system, source documents are decomposed into encapsulated data elements, in which a data element includes the actual content along with classifying data about the content. The encapsulated data elements are saved to a database, and can be later reassembled to form variation specific documents.

[0011] All of the systems described above involve the decomposition of source documents into smaller components, storing the document components in a database and reassembling the document components to form different variations of the source document, or completely new documents. While these systems facilitate the building of variation specific documents such as software documentation, and other engineering documents, they only involve combining and recombining static elements in various ways. The disclosed systems don't provide any way of generating a document “on the fly” that incorporates dynamically discovered information. Furthermore, none of the systems described concern themselves with optimizing the process of incorporating dynamic information into an online document by reducing the required computer resource usage.

[0012] Various other methods have been proposed for creating dynamic content in pages for delivery to a client over the Internet on the World-Wide Web (WWW). For example, JAVA SERVER PAGES from Sun Microsystems, Inc. of Menlo Park Calif. or ACTIVE SERVER PAGES from Microsoft Corporation of Redmond Wash. create all of the page content by having the page's Java or C++ server code write all of the page content to the client browser (the output stream). The major drawback of these solutions is that the server code and the page design (the HTML) are both contained in the same HTML file making it extremely difficult for non-programmers (e.g. graphic artists) to use popular page design tools to modify the content on these pages

[0013] The primary task of Internet Web server computers is to deliver content (Web pages) to client computers (Web browsers). These server computers are expected to perform these operations extremely rapidly because they are being besieged by, potentially, thousands and thousands of client requests per second. For this reason web developers attempt to reduce bottlenecks in the server software so that the server is performing up to its maximum capacity. The problem, then, arrives when many tokens in many dynamic pages need to be repeatedly replaced with dynamic content. Though the example in the preceding paragraph only contained a single token, the reality is that dynamic Web pages are normally far more complex than in this example, and might have 20 or more tokens.

[0014] Without any optimization, on each request, the server would have to re-read the base HTML file from disk, search and replace all occurrences of each token, and then write the newly created content stream to the client's return stream. The problem with this approach is that it is extremely time consuming. Even if the file is read from disk only once (i.e. it's cached) the act of replacing all occurrences of all tokens in the file is a very slow and very costly operation. It is so slow that it would likely be the primary bottleneck in the server software. Additionally, buying more hardware, bandwidth, etc. will not solve this problem because no matter how many machines were running concurrently, on each client request each web server would have to re-read and re-replace the page's content.

[0015] There exists, therefore, a need in the art for a way to reduce the processing overhead required to parse the HTML code of a web page that requires the incorporation of dynamic content in order to locate areas, identified by tokens, wherein the dynamic contented is to be inserted, and replacing the tokens with the dynamic content.

SUMMARY OF THE INVENTION

[0016] The invention provides a process in which an HTML file for a web page incorporating dynamic content is read and parsed once and only once throughout the life of the server. The dynamic HTML file is read from the server's local disk. A ContentComposer, a software object, parses the HTML and decomposes the page into its constituent pieces, which are stored in multiple data structures. The data structures and the ContentComposer are cached, allowing extremely rapid access. For subsequent page requests, the dynamic page is created from the in-memory version. This in-memory version can be shared across users and across requests. Reading and decomposing the HTML file and performing token replacement is so highly optimized that server resource usage, (memory, CPU, etc.) is near zero.

[0017] While the preferred embodiment provides a particular implementation directed to replacement of tokens in HTML files by a web server, it is generally applicable to any situation in which documents need to be

[0018] be editable using reasonable and current tools; and

[0019] be dynamic in that some of its content is static but other pieces of its content are created dynamically and will likely change from one creation to the next.

BRIEF DESCRIPTION OF THE DRAWINGS

[0020]FIG. 1 provides a top-level block diagram of a process for optimizing generation of a computer readable document incorporating static and dynamic content, according to the invention;

[0021]FIG. 2 provides a block diagram of a sub-process for “freeze-drying” raw content from a document template, according to the invention;

[0022]FIG. 3 provides a block diagram of a plurality of data structures for storing the freeze-dried content of FIG. 2, according to the invention; and

[0023]FIG. 4 provides a block diagram of a sub-process for composing a document from the freeze-dried content of FIG. 3, according to the invention.

DETAILED DESCRIPTION

[0024] Overview

[0025] A description of the details and function of the present invention is provided below. The source code listed in APPENDIX A, written in JAVA, details the implementation of a preferred embodiment of the invention. The patentee has no objection to the reproduction of the source code or other information for the purpose of obtaining and maintaining a valid patent. However, the patentee otherwise reserves all copyright interests.

[0026] The invention is embodied as both a process to be executed on a computer, typically a web server, and a computer program product providing computer readable program code means for executing the various steps of the process. The computer readable program code is embodied on a computer readable medium. The computer readable medium may be either fixed, such as a mass storage device or a memory, or it may be removable, such as a CD or a diskette. The invention is implemented through the use of conventional computer programming techniques well known to those skilled in the art. While the source code provided in the attached appendix is written in JAVA, other programming languages would also be suitable for programming the invention. While the invention is preferably programmed in an object-oriented language such as JAVA or C++, other embodiments, consistent with the spirit and scope of the invention, programmed in procedural languages or scripted languages, are also possible.

[0027] Referring now to FIG. 1, the invention provides a process for optimizing generation of a computer readable document incorporating static and dynamic content 10, particularly web pages being served up to a client in response to a request from a user. As previously mentioned, one of the most common ways of generating web pages having dynamic content is to start with a page template. Typically, the page template is a file of HTML code containing placeholders where the dynamic content is to be inserted. The placeholders usually consist of tokens. For example “@Username@” might be typically used as a placeholder for a user's name. When the template is created, or after it is edited, it is saved to disk, typically on a web server. Thereafter, the HTML file is read from the disk and parsed to locate the “live” or dynamic sections, which have been set off or reserved by the tokens. The invention provides a process in which the HTML file need be read from disk and parsed only once, unlike prior art methods, which require that the file be read and parsed every time a client requests the page.

[0028] File Reads

[0029] In the current embodiment of the invention, the HTML file is read from the disk 11 by means of a helper software object tasked with various utility file operations, such as reading in files, getting file lists and so on. Reading pages of “static” content is performed by a “getContent( )” method embodied in the helper object. The getContent(0 method of the helper object retrieves the raw HTML file and stores the raw content to the cache as a string. More detailed descriptions of the operation of the helper object and the “getContent( )” method are to be found by referring to the documentation provided in the enclosed Appendix.

[0030] Content Composer

[0031] When parsing the HTML file for caching and token replacement purposes, the goal is to separate the HTML file into its component static pieces, dynamic pieces, and replaceable token pieces. A common term of art for this process is “freeze-drying” 12. The invention provides a ContentComposer class that is the sole parser and manager of this freeze-dried content. Each HTML file has a separate instance of the ContentComposer object associated with it. In keeping with conventional methods of object-oriented programming, in which an object includes both instructions and the associated data, the ContentComposer object for a particular page includes the implementation logic and the raw content string. When a file is loaded, the helper object checks to see if a ContentComposer object exists for the file. If the file has no associated ContentComposer object, the helper object creates one 20. A global HashMap, held in the cache, provides storage for ContentComposer objects. Thus, following creation of the ContentComposer, the new ContentCompser object is stored to the global Hashmap. In this way, the deconstructed file data is effectively cached, so that it may be used on subsequent invocations 21.

[0032] After being cached, ContentComposer parses the HTML file by “decomposing” the raw code string, separating it into its various components 22. Components are one of three types:

[0033] blocks of immutable content containing no tokens;

[0034] lines of immutable content that surround tokens; and

[0035] token replacement values.

[0036] According to a preferred embodiment of the invention, a token comprises a string that starts and ends with the “@” characters and contains no embedded white space, newline characters, colons, semi-colons, or commas. However, the delimiting characters are a mere matter of choice, dictated in this case by the conventional manner of creating tokenized HTML code.

[0037] In some cases, only the token is replaced, in other cases, the entire line containing the token is replaced. For example, the method allows calling processes to replace the whole line of text that the token was on, which is a frequent operation for callers replacing <ii> or <select> items.

[0038] As previously described, the helper object provides a raw code string to the ContentComposer for parsing. A setContents( ) method within the ContentComposer provides most of the parsing logic for the invention. The setContents( ) method parses the raw content string to locate delimiting characters. Upon locating a delimiting character, the parsing engine evaluates the string for the presence of the previously indicated illegal characters—white space, newline characters, colons, semi-colons, or commas. The presence of any illegal characters indicates that the delimiting, character is not associated with a valid token. “@foo bar@” or “keith@iamaze.com” are examples of such invalid strings. As the various page components are identified, they are stored to one of several data objects that are also associated with the ContentComposer. After the page components are identified, the page is decomposed by saving the separate components to a plurality of data structures 23. These data structures are described in greater detail below. It should be noted that the process of separating the page into components and storing them in the data structures constitutes the process commonly known as “freeze-drying.” While, for the purpose of description, the data and the data structures are described separately from the logic and instructions, they are, in fact, all associated within a single ContentComposer object, which is held in the cache. Thus, as with the raw code string, the data structures containing the page components are effectively cached, eliminating the necessity of any further disk accesses when the HTML file is composed.

[0039] After the page components are cached, calling processes can ask the ContentComposer to perform token replacment, which it can do very fast: in 0-1 time, the tokens are stored in a HashMap as described below. The final part of SXContentComposer's lifecycle is when the caller asks the ContentComposer to “compose( )” itself, thus creating a page for download to a client 13. The compose( ) method itself provides additional important performance gains. Rather than recomposing the HTML into a string, and passing the string to the calling process, extremely wasteful of memory and processor time, the ContentComposer walks through the data structures and writes the data to an output stream as it is walking 14.

[0040] This implementation holds three primary data structures. It is necessary to hold this parsed data in three disparate, but linked, data structures because the data must be accessed from a number of different “angles”, and for a number of different purposes. The composer will need access to all the original static text, plus some way to gather the token replacement values. The caller will need to replace token values (by specifying the token name), or the whole line the token is appears on. The caller may also want to inspect the line a token appears on.

[0041] Data Structures

[0042] The three primary data structures are as follows:

[0043] The first is an array of immutable content broken up into “chunks” 30. Each chunk is either a text block with no “@foo@” tokens, or it is an integer object pointing to the index of a token replacement object, (SXTokenLine) which will supply the values (string) for that chunk.

[0044] The second data structure is also an array of immutable content: an array of the token-replacement-objects mentioned above 31, and pointed to by the chunks array. These token-replacement-objects are of type Token Line and they hold the static text that immediately precedes and follows a token. They also hold the raw token name itself (e.g. “@FooBar@”) as well as a pointer to an object stored within the third data structure, a structure that holds the replacement line or replacement value associated with this token. This final object is of type Token. While the names assigned to the various page component types in the current embodiment are descriptive of their content, they are primarily a matter of choice.

[0045] The third data structure is a HashMap with all the tokens from the raw content as keys and all the replacement values set by the calling process as the values 32. These replacement values are of type Token Object, which can hold a replacement line or a replacement value for a token.

[0046] Note that the immutable text chunks never change throughout the life of this object, while the values stored in the tokens and replacement values HashMap are likely to change every time content is created, since tokens and replacement values represent the dynamic portion of the content.

[0047] Furthermore, to reduce the overhead of future writes to streams, and to reduce the excessive creation of string objects, the static data in both the immutable text chunks array as well as the immutable token lines array is stored as byte( ), rather than string.

[0048] Compose( ) Method

[0049] The Compose( ) method of the ContentComposer writes each text chunk and token replacement value to an output stream in sequential order, creating a single, coherent, token-replaced text stream.

[0050] As the ContentComposer walks the immutable text chunks array 40, if it encounters an array entry that is a token rather than a chunk of text, instead of concatenating the actual token, it concatenates the value for the token found in the tokens and replacement values HashMap 41.

[0051] The specific process and data structures used by the ContentComposer are described in greater detail in the example provided below.

EXAMPLE

[0052] Sample Raw Content:

[0053] <html>

[0054] <title> iAmaze Presentation Tool </title>

[0055] <h1> Welcome to iAmaze, @UserName@!</h1>

[0056] <br>

[0057] <br>

[0058] Would you like to work on the presentation you last worked on, named

[0059] @LastPresentation@?

[0060] <br>

[0061] If so, click here.

[0062] </html>

[0063] SAMPLE RAW DATA STRUCTURES CREATED FROM RAW CONTENT:

[0064] Immutable text chunks array:

[0065] immutableTextChunksArray[0]=“<html>

[0066] <title> iAmaze Presentation Tool </title>”

[0067] immutableTextChunksArray[1]=“new integer(0)” (use to look up, at index=0, this token's pre- & post-SXTokenLine line text objects in the “immutableTokenLines” array.)

[0068] immutableTextChunksArray[2]=“!</h1>

[0069] <br>

[0070] <br>”

[0071] immutableTextChunksArray[3]=“new Integer(1)” (index into “immutableTokenlLines” array, above and below)

[0072] immutableTextChunksArray[4]=“?

[0073] <br>

[0074] If so, click-here. </html>”

[0075] Immutable token lines array:

[0076] ImmutableTokenLinesArray[0]=SXTokenLine{prefix=“<h1>Welcome to iAmaze,” suffix=“!</h1>”, pointer to SXToken object in the tokensAndReplacementValues}

[0077] ImmutableTokenLinesArray[1]={SXTokenLine{prefix=“Would you like to work on the presentation you last worked on, named: “, suffix=””,pointer to SXToken object in the tokensAndReplacementValues}

[0078] Tokens and replacement values HashMap:

[0079] TokensAndReplacementValues={

[0080] {“@UserName@”,SXToken{replacementForToken=null, replacementForTokenLine=null}},

[0081] {“@LastPresentation@”, SXToken{replacementForToken=null, replacementForTokenLine==nulll}}}

[0082] Thus, the data structures for the example page appear as shown above immediately after the parsing or “freeze-dry” process. After being supplied values by calling process, for example, in response to a request from a user, two separate methods are called to replace the tokens with the new content:

[0083] After calls to:

[0084] anSXContentComposer.replaceLineContainingToken(“@UserName@”,“<h1>Welcome to work, Keith!</h1>”);

[0085] anSXContentComposer.replaceToken(“@LastPresentation@”,“1999 Harleys”);

[0086] The tokens and replacement values HashMap look as below:

[0087] tokensAndReplacementValues=

[0088] {{“@UserName@”,SXToken{replacementFortoken=null, replacementForTokenLine=“<h1>Welcome to work, Keith!</h1>”}},

[0089] {“@LastPresentation@”, SXToken {replacementForToken=“1999Harleys”, replacementForTokenLine=null}}}

[0090] The first call replaces the entire line containing the token. The second call replaces only the token. The immutable text chunks and the immutable token lines arrays remain the same, since they contain immutable data.

[0091] A call to SXContentComposer's Compose( ) or tostring( ) methods generates the following:

[0092] <html>

[0093] <title> iAmaze Presentation Tool </title><h1>Welcome to work, Keith!</title>

[0094] <br>

[0095] <br>

[0096] Would you like to work on the presentation you last worked on, named 1999 Harleys?<br>

[0097] If so, click here.

[0098] </html>

[0099] The tostring( ) method outputs a string to the output stream in a fashion similar to the Compose( ) method. More detailed description of the tostring( ) method as well as the replaceLineContainingToken( ), and replaceToken( ) methods is to be found below.

[0100] Although the invention has been described herein with reference to certain preferred embodiments, one skilled in the art will readily appreciate that other applications may be substituted without departing from the spirit and scope of the present invention. Accordingly, the invention should only be limited by the claims included below. 

1. A process for optimizing generation of a computer readable document incorporating static and dynamic content, comprising the steps of: creating and caching an instance of a first software object, said first software object including: a template for said document, said template including placeholders for dynamically-discovered content; a plurality of data structures; and computer-readable instructions for processing said template; decomposing said template into separate page components according to said instructions; saving said page components and said dynamically-discovered content to said data structures according to said instructions; receiving a request for said document; and composing said document by said first software object; wherein a separate instance of said software object is created and cached for each document.
 2. A process according to claim 1, wherein the step of creating and caching an instance of said first software object comprises the steps of: retrieving said template by a second software object, said template comprising an HTML file; creating an instance of said first software object for said file, if one does not already exist, said instance including said HTML file as a string; and storing said instance to a global hashmap, said global hashmap held in said cache, wherein said first software object comprises a content composer.
 3. A process as in claim 2, wherein said step of decomposing said template comprises the steps of: parsing said template string by said content composer; and locating placeholders in said template for said dynamic content.
 4. The process of claim 2, wherein said placeholders comprise tokens, and wherein said document components comprise: blocks of immutable content, having no tokens therein; token replacement objects, said token replacement objects comprising blocks of static text preceding and following a token; and raw token names.
 5. The process of claim 4, wherein said document components further comprise replacement values and replacement lines for said tokens, wherein said replacement values and replacement lines comprise said dynamic content.
 6. The process of claim 5, wherein said step of saving said components and said dynamically discovered content comprises the steps of: converting said components into byte streams; and saving said byte streams to said data structures.
 7. The process of claim 6, wherein said data structures comprise: a first array of immutable content containing any of: said blocks of immutable content and integer objects pointing to indices of one or more objects in a second array; said second array, containing said token replacement objects and said raw token names, wherein blocks of immutable content having tokens therein are built from said token replacement objects and said raw token names, and wherein raw token names further include pointers to corresponding keys in a third data structure; and a hash map, said hash map comprising said third data structure, wherein keys of said hash map comprise said raw token names and wherein values comprise replacement values and replacement lines for said tokens.
 8. The process of claim 7, wherein said step of composing said document comprises: walking said data structures and writing said data to a stream as it walks through the data structures, so that a document is created wherein said tokens are replaced with either of said replacement values or said replacement lines.
 9. The process of claim 2, wherein said cache and said template are located on a server and said request is received from a client in communication with said server.
 10. The process of claim 9, wherein said dynamically discovered content comprises content received from said client.
 11. A computer program product for optimizing generation of a computer readable document incorporating static and dynamic content, said computer program product comprising a computer usable storage medium having computer readable computer code means embodied in the medium, the computer code means comprising computer readable program code means for: creating and caching an instance of a first software object, said first software object including: a template for said document, said template including placeholders for dynamically-discovered content; a plurality of data structures; and computer-readable instructions for processing said template; decomposing said template into separate page components according to said instructions; saving said page components and said dynamically-discovered content to said data structures according to said instructions; receiving a request for said document; and composing said document by said first software object; wherein a separate instance of said software object is created and cached for each document.
 12. A computer program product according to claim 11, wherein the computer readable code for creating and caching an instance of said first software object comprises computer readable code for: retrieving said template by a second software object, said template comprising an HTML file; creating an instance of said first software object for said file, if one does not already exist, said instance including said HTML file as a string; and storing said instance to a global hashmap, said global hashmap held in said cache, wherein said first software object comprises a content composer.
 13. A computer program product as in claim 12, wherein said computer readable code for decomposing said template comprises the computer readable code for: parsing said template string by said content composer; and locating placeholders in said template for said dynamic content.
 14. A computer program product as in claim 12, wherein said placeholders comprise tokens, and wherein said document components comprise: blocks of immutable content, having no tokens therein; token replacement objects, said token replacement objects comprising blocks of static text preceding and following a token; and raw token names.
 15. A computer program product as in claim 14, wherein said document components further comprise replacement values and replacement lines for said tokens, wherein said replacement values and replacement lines comprise said dynamic content.
 16. A computer program product as in claim 15, wherein said computer readable code for saving said components and said dynamically discovered content comprises the computer readable code for: converting said components into byte streams; and saving said byte streams to said data structures.
 17. A computer program product as in claim 16, wherein said data structures comprise: a first array of immutable content containing any of: said blocks of immutable content and integer objects pointing to indices of one or more objects in a second array; said second array, containing said token replacement objects and said raw token names, wherein blocks of immutable content having tokens therein are built from said token replacement objects and said raw token names, and wherein raw token names further include pointers to corresponding keys in a third data structure; and a hash map, said hash map comprising said third data structure, wherein keys of said hash map comprise said raw token names and wherein values comprise replacement values and replacement lines for said tokens.
 18. A computer program product as in claim 17, wherein said computer readable code for composing said document comprises computer readable code for: walking said data structures and writing said data to a stream as it walks through the data structures, so that a document is created wherein said tokens are replaced with either of said replacement values or said replacement lines.
 19. A computer program product as in claim 12, wherein said cache and said template are located on a server and said request is received from a client in communication with said server.
 20. A computer program product as in claim 19, wherein said dynamically discovered content comprises content received from said client 